from django.db import models
from django.conf import settings


class Inspiration(models.Model):
    """灵感库模型"""
    
    # 灵感类型选项
    TYPE_CHOICES = [
        ('text', '文字'),
        ('image', '图片'),
        ('audio', '音频'),
    ]
    
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL, 
        on_delete=models.CASCADE, 
        related_name='inspirations',
        db_comment='用户ID'
    )
    type = models.CharField(
        max_length=20, 
        choices=TYPE_CHOICES,
        db_comment='灵感类型'
    )
    content = models.TextField(
        db_comment='灵感内容'
    )
    tags = models.CharField(
        max_length=200, 
        blank=True, 
        null=True,
        db_comment='标签'
    )
    created_at = models.DateTimeField(
        auto_now_add=True,
        db_comment='创建时间'
    )
    
    class Meta:
        db_table = 'creation_inspirations'
        db_table_comment = '用户灵感库表'
        verbose_name = '灵感'
        verbose_name_plural = '灵感管理'
        ordering = ['-created_at']
        indexes = [
            models.Index(fields=['user']),
            models.Index(fields=['type']),
            models.Index(fields=['created_at']),
        ]
    
    def __str__(self):
        return f"{self.user.username} 的灵感 - {self.get_type_display()}"
